#include "ShaderResourceManager.h"
#include "Shader.h"
#include "NeroEngine\NFileSystem.h"
#include "NeroEngine\NPlatform.h"

using namespace Graphics;

ShaderResourceManager* ShaderResourceManager::sInstance = NULL;

ShaderResourceManager::ShaderResourceManager(void)
	:NResourceManager<Graphics::Shader>(&Graphics::CreateShaderResource)
{
}

ShaderResourceManager::~ShaderResourceManager(void)
{
	ResourceMap::iterator _it = mResources.begin();
	for(; _it != mResources.end(); _it++)
	{
		MY_DELETE((*_it).second);
		(*_it).second = NULL;
	}
}

void ShaderResourceManager::Initialize()
{
	if(!sInstance)
	{
		sInstance = MY_NEW(Memory::HID_Rendering, "ShaderResourceManager") ShaderResourceManager();
		Engine::NFileSystem* fileSys = GetPlatform()->GetFileSystem();
		if(fileSys)
		{
			fileSys->Load("..\\..\\assets\\xml\\Assets_Shader.xml");
		}
	}
}

void ShaderResourceManager::Deinitialize()
{
	if(sInstance)
	{
		MY_DELETE(sInstance);
		sInstance = NULL;
	}
}

ShaderResourceManager* ShaderResourceManager::GetInstance()
{
	return sInstance;
}